<!DOCTYPE html>
<?php
$first=!($_POST);
   
?>

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
       if($first){
            echo "无post第一次访问;渲染页码";
        ?>
       
           <form action="myadd.php" method="post" enctype="multipart/form-data">
               账号：<input type="text" name="uname"></br>
               密码：<input type="password" name="upasswd"></br> 
               性别：<input type="text" name="sex"></br>
               年龄： <select name="age">
                        <?php
                        for($i;$i<120;$i++){
                            echo "<option >$i</option>";
                        }
                         ?>
                    </select>    
                </br>
               班级：<input type="text" name="clss"></br>
               头像图片：<input type="file" name="myipx"></br>
               <input type="submit" value="注册">
               <input type="reset" vlaue="取消">
            </form>
     <?php      
     
    }else{
        echo "得到post二次访问，处理数据";
            $uage=$_POST["age"];
            $uname=$_POST["uname"];
            $upwd=$_POST["upasswd"];
            $sex=$_POST["sex"];
            $uclass=$_POST["clss"];

            $newurl="./img/".time()."_".$_FILES["myipx"]["name"];
            move_uploaded_file($_FILES["myipx"]["tmp_name"], $newurl);
            
            
        $hostname="127.0.0.1";
        $username="root";
        $password="123456";
        $database="mysql123";

        $connet=mysqli_connect($hostname, $username, $password, $database);
        mysqli_set_charset($connet, "utf-8");
        
        if($connet){
           $sqlstring="insert into user_inf(uname,sex,age,class,upasswd,ipx) "
                  ." values('$uname','$sex','$uage','$uclass','$upwd','$newurl')";
              $result= mysqli_query($connet, $sqlstring);
//            $row= mysqli_fetch_array($result);
              mysqli_close($connet);
        }
        
        
        
    }
  
       ?>
    </body>
</html>
